package com.briup.smartlabs.utils;

import lombok.Data;

@Data
public class Result<O> {
    private Integer code;
    private String message;
    private O data;
    private Long requestTime;
    public Result(ResultCode resultCode, O data){
        this.code = resultCode.getCode();
        this.message = resultCode.getMsg();
        this.data = data;
        this.requestTime = System.currentTimeMillis();
    }
    private Result(){


    }

    public static <O> Result<O> success(){
        return success(null);
    }

    public static <O> Result<O> success(O data){
        return failure(ResultCode.SUCCESS,data);


        }
    public static <O> Result<O> failure(ResultCode resultCode,O data){
        return new Result<>(resultCode,data);
    }
    public static Result<?> customResultCode(Integer code, String msg){
        Result<?> result = new Result<>();
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }

}
